package com.hmall.item.send;

import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class ItemSender {

    private final RabbitTemplate rabbitTemplate;

    public void sendAdd(Long itemId) {
        rabbitTemplate.convertAndSend("item.direct", "add", itemId);
        System.out.println("发送新增商品消息：" + itemId);
    }

    public void sendUpdate(Long itemId) {
        rabbitTemplate.convertAndSend("item.direct", "update", itemId);
        System.out.println("发送修改商品消息：" + itemId);
    }

    public void sendDelete(Long itemId) {
        rabbitTemplate.convertAndSend("item.direct", "del", itemId);
        System.out.println("发送删除商品消息：" + itemId);
    }
}
